home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / win / c / doswin.com / TESTWIN.C < prev   
Encoding:
C/C++ Source or Header  |  1990-10-12  |  2.5 KB  |  123 lines

  1. //
  2. //    (c) Bill Carter 1990
  3. //
  4. //    Demonstration of capturing DOS output in a window
  5. //
  6. //    Note:  puts() & printf() respect this window.
  7. //
  8. //      Although this routine will not window everything
  9. //    it will place *most* DOS output in a window.
  10. //
  11. //    This code is provide AS IS, USE AT YOUR OWN RISK!
  12. //
  13. //    Written using QC/QAsm 2.51
  14. //
  15. //    Usable with Small,Compact,Medium,Large, and Huge memory models
  16. //
  17. //    Incompatible with Tiny memory model
  18. //
  19. //    Add DWin.Obj to your make list
  20. //
  21.  
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24. #include <graph.h>
  25. #include <conio.h>
  26.  
  27. #define CLEARWIN        1
  28. #define LEAVEWIN    0
  29.  
  30. //    DosWinInit returns 0 if it fails
  31. //               1 if it succeeds
  32. //
  33. //    It can fail for the following reasons
  34. //
  35. //        #1.  DosWinInit is already active
  36. //        #2.  Window dimensions are incorrect
  37. //            (assumes screen is 25 X 80)
  38. //
  39.  
  40. extern _far DosWinInit(char UpperRow,char LeftColumn, char LowerRow,
  41.     char RightColumn,int ClearWindowFlag) ;
  42.  
  43. //      DosWinRel returns 0 if it fails
  44. //              1 if it succeeds
  45. //
  46. //    Fails only if DosWinInit is not active.
  47. //
  48.  
  49. extern _far DosWinRel(void);
  50.  
  51. void SetWindow( char tr, char lc, char br, char rc );
  52. void prepare(void);
  53.  
  54. void main( void )
  55.     {
  56.     int cnt;
  57.     _clearscreen( _GCLEARSCREEN ) ;
  58.  
  59.     _settextposition( 8,20);
  60.     puts( "DOS DIR in a window");
  61.     SetWindow( 9,4,21,51);
  62.     system( "Dir" ) ;
  63.     DosWinRel();
  64.     prepare();
  65.  
  66.     _settextposition(3,20);
  67.     puts( "DOS TYPE in a larger window");
  68.     SetWindow(4,4,21,71);
  69.     system( "TYPE testwin.c");
  70.     DosWinRel();
  71.     prepare();
  72.  
  73.     _settextposition(3,7);
  74.     puts( "COMMAND.COM in a window.  Type EXIT to return to this demo." ) ;
  75.     SetWindow(10,1,20,79);
  76.     system( "COMMAND");
  77.     DosWinRel();
  78.     prepare();
  79.     exit(0);
  80.     }
  81.  
  82. // Setup window
  83.  
  84. void SetWindow( char tr, char lc, char br, char rc )
  85.     {
  86.     int cnt;
  87.     _settextposition( tr, lc);
  88.     putch( '┌' ) ;
  89.     _settextposition( tr, rc);
  90.     putch( '┐' ) ;
  91.     _settextposition( br, lc);
  92.     putch( '└' ) ;
  93.     _settextposition( br, rc);
  94.     putch( '┘' );
  95.     for ( cnt = tr+1; cnt < br; cnt++)
  96.         {
  97.         _settextposition( cnt,lc);
  98.         putch( '│' );
  99.         _settextposition( cnt,rc);
  100.                 putch( '│' );
  101.         }
  102.     for ( cnt = lc+1; cnt < rc ; cnt++)
  103.         {
  104.         _settextposition( tr,cnt);
  105.         putch( '─');
  106.         _settextposition( br,cnt);
  107.                 putch( '─');
  108.         }
  109.     if ( !DosWinInit( ++tr, ++lc, --br, --rc, CLEARWIN))
  110.         {
  111.         puts( "Error initializing window." ) ;
  112.         exit(-1);
  113.         }
  114.     }
  115.  
  116. void prepare(void)
  117.     {
  118.     _settextposition( 24,1);
  119.     printf( "press any key.");
  120.     getch();
  121.     _clearscreen( _GCLEARSCREEN);
  122.     }
  123.